package org.springblade.modules.admin.controller.es;

import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springblade.modules.admin.dto.es.SearchParamDTO;
import org.springblade.modules.admin.entity.es.ElevatorDocument;
import org.springblade.modules.admin.service.IElevatorSearchService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@AllArgsConstructor
@RestController
@Api(value = "电梯搜索", tags = "电梯搜索接口")
@RequestMapping("/es-elevator-search")
public class EsElevatorSearchController {

	private final IElevatorSearchService esElevatorSearchService;

	/**
	 * 初始化数据
	 *
	 * @return
	 */
	@GetMapping("init")
	public void init() {
		esElevatorSearchService.init();
	}

	/**
	 * PUT /test_elevator_document
	 * {
	 *    "settings": {
	 *         "analysis": {
	 *             "analyzer": {
	 *                 "custom_pinyin": {
	 *                     "type": "custom",
	 *                     "tokenizer": "ngram_tokenizer",
	 *                     "filter": ["my_pinyin"]
	 *                 },
	 *                 "ngram_analyzer": {
	 *                     "tokenizer": "ngram_tokenizer"
	 *                 }
	 *             },
	 *             "filter": {
	 *                 "my_pinyin": {
	 *                     "type": "pinyin",
	 *                     "keep_first_letter": true,
	 *                     "keep_separate_first_letter": true,
	 *                     "limit_first_letter_length": 16,
	 *                     "keep_full_pinyin": true,
	 *                     "keep_joined_full_pinyin": false,
	 *                     "keep_original": false,
	 *                     "none_chinese_pinyin_tokenize": false,
	 *                     "keep_none_chinese_in_joined_full_pinyin": true
	 *                 }
	 *             },
	 *              "tokenizer": {
	 *                 "ngram_tokenizer": {
	 *                   "type": "ngram",
	 *                   "min_gram": 1,
	 *                   "max_gram": 1,
	 *                   "token_chars": [
	 *                     "letter",
	 *                     "digit",
	 *                     "punctuation",
	 *                     "symbol"
	 *                   ]
	 *                 }
	 *             }
	 *       }
	 *   }
	 * }
	 *
	 *
	 * POST /test_elevator_document/_mapping
	 * {
	 *   "properties": {
	 *     "name": {
	 *       "type": "text",
	 *       "analyzer": "ngram_analyzer",
	 *       "search_analyzer": "ngram_analyzer"
	 *     },
	 *     "alias": {
	 *       "type": "text",
	 *       "analyzer": "ngram_analyzer",
	 *       "search_analyzer": "ngram_analyzer"
	 *     },
	 *    "namePinyin":{
	 *       "type": "text",
	 *       "analyzer": "custom_pinyin",
	 *       "search_analyzer": "custom_pinyin"
	 *     },
	 *     "aliasPinyin":{
	 *       "type": "text",
	 *       "analyzer": "custom_pinyin",
	 *       "search_analyzer": "custom_pinyin"
	 *     }
	 *   }
	 * }
	 */

	/**
	 * 根据名称查询(包含)
	 *
	 * @param searchParam
	 * @return
	 */
	@GetMapping("/listByTitle")
	public R<List<ElevatorDocument>> listDocumentByTitle(SearchParamDTO searchParam) {
		return R.data(esElevatorSearchService.listDocumentByTitle(searchParam));
	}
}
